package yt.demo.demoadmin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yt.demo.appcommonbean.http.DeleteRequest;
import yt.demo.appcommonbean.http.RestResponse;
import yt.demo.appcommondb.dto.SplitPageDTO;
import yt.demo.appcommondb.vo.PageVO;
import yt.demo.appcoresystem.entity.SystemOperLog;
import yt.demo.appcoresystem.service.ISystemOperLogService;

@RestController
@RequestMapping("/operLog")
public class OperLogController extends BaseController {

    private final ISystemOperLogService service;

    @Autowired
    public OperLogController(ISystemOperLogService service) {
        this.service = service;
    }

    @GetMapping("/getPageList")
    public RestResponse<PageVO<SystemOperLog>> getPageList(SplitPageDTO page, SystemOperLog params) {
        return RestResponse.ok(this.service.getPageList(page, params, w-> w.orderByDesc(SystemOperLog::getId), null));
    }

    @PostMapping("/delete")
    public RestResponse<Void> delete(@RequestBody DeleteRequest req) {
        this.service.delete(req);
        return RestResponse.ok();
    }

    @GetMapping("/detail")
    public RestResponse<SystemOperLog> detail(@RequestParam("id") Long id) {
        return RestResponse.ok(this.service.detail(id));
    }

}
